package fr.coupedumonde2014.app.activity;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.widget.ListView;
import android.widget.TextView;

import com.astuetz.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

import fr.coupedumonde2014.app.R;
import fr.coupedumonde2014.app.adapter.TabsPagerAdapter;
import fr.coupedumonde2014.app.modele.Match;
import fr.coupedumonde2014.app.modele.Utilisateur;


public class ListMatch extends FragmentActivity implements
        ActionBar.TabListener {

    public static ListMatch instance;
    ListView listMatches;
    public static List<Match> matchesAVenir = new ArrayList<Match>();
    public static List<Match> matchesParis = new ArrayList<Match>();
    public static List<Utilisateur> classement = new ArrayList<Utilisateur>();

    private TabsPagerAdapter adapter;

    ViewPager viewPager;
    PagerSlidingTabStrip onglets;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_match);

        instance = this;

        charger();
        remplir();
        ajouterListeners();
    }

    @Override
    public void onResume()
    {
        super.onResume();
        personnaliserActionBar();
    }

    public void refresh(){
        adapter.refresh();
    }

    private void personnaliserActionBar(){
        this.getActionBar().setDisplayShowCustomEnabled(true);

        int titleId = getResources().getIdentifier("action_bar_title", "id",
                "android");

        int subtitleId = getResources().getIdentifier("action_bar_subtitle", "id",
                "android");

        this.getActionBar().setTitle(getResources().getString(R.string.app_name));
        this.getActionBar().setSubtitle(getResources().getString(R.string.sous_titre));
       // actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.black)));

        TextView actionBarTitle = (TextView) findViewById(titleId);
        TextView actionBarSubTitle = (TextView) findViewById(subtitleId);

        Typeface face;
        face = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");
        actionBarTitle.setTypeface(face);
        actionBarTitle.setTextColor(getResources().getColor(R.color.white));
        face = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
        actionBarSubTitle.setTypeface(face);
        actionBarSubTitle.setTextColor(getResources().getColor(R.color.white));

        this.getActionBar().setHomeButtonEnabled(false);
        //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    }

    private void charger() {
        viewPager = (ViewPager) findViewById(R.id.pager);
        onglets = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    }

    public void remplir(){
        // Initilization

        adapter = new TabsPagerAdapter(getSupportFragmentManager(),this);
        viewPager.setAdapter(adapter);

        // Bind the tabs to the ViewPager
        onglets.setViewPager(viewPager);
    }

    public void ajouterListeners(){

    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        // on tab selected
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

}
